package com.doodle.common.utils;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.provider.MediaStore;
import android.telephony.TelephonyManager;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.widget.AbsListView;

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.Collator;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Formatter;
import java.util.Locale;

public class Utils {
    private static final String TAG = "Utils";
	
	public static boolean SHOW_LOG = true;
	public static boolean SAVE_LOG_TO_FILE = false;

	private static final String[] FILE_PATH_PROJ = { MediaStore.MediaColumns.DATA };
	private static final Method sGetStorageDirMethod;
	
	static {
		sGetStorageDirMethod = getGetStorageDirMethod();
	}
	
	private static Method getGetStorageDirMethod() {
		try {
			return Environment.class.getMethod("getExternalStorageDirectoryMzInternal");
		} catch (Exception e) {
			return null;
		}
	}
	
	public static void assertTrue(boolean cond) {
        if (!cond) {
            throw new AssertionError();
        }
    }
	
	public static void assertTrue(boolean cond, String message) {
        if (!cond) {
            throw new AssertionError(message);
        }
    }
	
	public static <T> T checkNotNull(T reference) {
        if (reference == null) {
            throw new NullPointerException();
        }
        return reference;
    }
	
    public static <T> T checkNotNull(T reference, Object errorMessage) {
        if (reference == null) {
            throw new NullPointerException(String.valueOf(errorMessage));
        }
        return reference;
    }

	public static float clamp(float x, float min, float max) {
	    return x > max ? max : (x < min ?  min : x);
	}
	
	public static int clamp(int x, int min, int max) {
        return x > max ? max : (x < min ?  min : x);
    }
	
	public static void closeSilently(Closeable c) {
        if (c == null) return;
        try {
            c.close();
        } catch (Throwable t) {
            Log.w("Utils", "close fail", t);
        }
	}
	
    public static String getFilePathFromUri(Context context, Uri uri) {
	   	String str = null;
	   	ContentResolver resolver = context.getContentResolver();
		Cursor cursor = null;
		try {
			cursor = resolver.query(uri, FILE_PATH_PROJ, null, null, null);
			if (cursor != null && cursor.moveToFirst()) {
	           	str = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA));
			}
		} finally {
			closeSilently(cursor);
		}
	   	return str;
	}
    
    public static long checkRelativeTime(long time) {
    	long nowTime = System.currentTimeMillis();
    	if (nowTime - time * 1000L < 60000L) {
    		return nowTime - 61000L;
    	}
    	return time * 1000L;
    }
    
	public static String execCommand(String cmd, boolean isSingleLine) {
		String s = null;
		InputStreamReader streamReader = null;
		BufferedReader bufferedReader = null;
		try {
			Process p = Runtime.getRuntime().exec(cmd);
			InputStream is = p.getInputStream();
			streamReader = new InputStreamReader(is);
        	bufferedReader = new BufferedReader(streamReader);
			if (isSingleLine) {
				s = bufferedReader.readLine();
			} else {
				s = "";
				String line = null;
				while ((line = bufferedReader.readLine()) != null) {
					s += line + "\n";
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			Utils.closeSilently(bufferedReader);
			Utils.closeSilently(streamReader);
		}
		return s;
	}
	
	private static String sPhoneIMEI;
	private static String sNetworkOperator;
	private static String sAppVersionCode;
	
	public synchronized static String getPhoneIMEI(Context context) {
		if (sPhoneIMEI == null) {
			TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
			sPhoneIMEI = tm.getDeviceId();
		}
		return sPhoneIMEI;
	}
	
	public synchronized static String getAppVersionCode(Context context) {
		if (sAppVersionCode == null) {
			try {
				PackageManager packageManager = context.getPackageManager();
				PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
				sAppVersionCode = packInfo.versionName;
			} catch (NameNotFoundException e) {
				e.printStackTrace();
			}
		}
		return sAppVersionCode;
	}
	
	public synchronized static String getNetworkOperator(Context context) {
		if (sNetworkOperator == null) {
			TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
			sNetworkOperator = tm.getNetworkOperatorName();
		}
		return sNetworkOperator;
	}
	
	public static void log(String format, Object... args) {
		if (!SHOW_LOG) {
			return;
		}
		String str = String.format(format, args);
		if (SAVE_LOG_TO_FILE) {
			saveLogToFile(str);
		}
		Log.d("Utils", str);
	}
	
	public static void log(boolean showLog, boolean saveToFile, String format, Object... args) {
		if (!showLog && !saveToFile) {
			return;
		}
		String str = String.format(format, args);
		if (saveToFile) {
			saveLogToFile(str);
		}
		if (showLog) {
			Log.d("Utils", str);
		}
	}
	
	private static String sLogFileLocation = null;
	public static void setLogFileLocation(String location) {
		sLogFileLocation = location;
	}
	
	public static void saveLogToFile(String log) {
		String location = sLogFileLocation;
		if (isEmpty(location)) {
			location = getExternalStorageDirectory() + "/Android/data/com.draw.media.common/";
		}
		
		File file = new File(location);
		if (!file.exists()) {
			file.mkdirs();
		}
		try {
			file = new File(location + "network.txt");
			OutputStream out = new FileOutputStream(file, true);
			out.write(log.getBytes());
			out.write("\r\n".getBytes());
			out.close();
			
			if (file.length() > 1024 * 1024) {
				file.delete();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private static final DecimalFormat sPriceFormatter = new DecimalFormat("#0.0");
	
	public static String getPriceTag(BigDecimal price) {
		return "￥" + sPriceFormatter.format(price);
	}
	
	public static String getPriceTag(Double price) {
		return "￥" + sPriceFormatter.format(price);
	}
	
	private static final DecimalFormat sPriceWithCentFormatter = new DecimalFormat("#0.00");
	
	public static String getPriceWithCentTag(double price) {
		return "￥" + sPriceWithCentFormatter.format(price);
	}
	
	private static final int DATE_STRING_FLAGS = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_ABBREV_MONTH;
	
	public static String getDateString(Context context, long millisec) {
		return DateUtils.formatDateTime(context, millisec, DATE_STRING_FLAGS);
	}
	
	private static StringBuilder sFormatBuilder;
    private static Formatter sFormatter;
    private static Object[] sTimeArgs;
    private static String sDurationFormatLong;
    private static String sDurationFormatShort;
    
    public static void initTimeStringMaker(Context context) {
    	sFormatBuilder = new StringBuilder();
    	sFormatter = new Formatter(sFormatBuilder, Locale.getDefault());
    	sTimeArgs = new Object[5];
    	sDurationFormatLong = ""/*context.getString(R.string.media_duration_format_long)*/;
    	sDurationFormatShort = ""/*context.getString(R.string.media_duration_format_short)*/;
    }

    public static String makeTimeString(long secs, boolean forcehour) {
        String durationformat = (secs > 3600 || forcehour) ? sDurationFormatLong : sDurationFormatShort;
        
        sFormatBuilder.setLength(0);

        final Object[] timeArgs = sTimeArgs;
        timeArgs[0] = secs / 3600;
        timeArgs[1] = secs / 60;
        timeArgs[2] = (secs / 60) % 60;
        timeArgs[3] = secs;
        timeArgs[4] = secs % 60;

        return sFormatter.format(durationformat, timeArgs).toString();
    }

    private static Collator sBetterCompareCollator = null;
    private static boolean sIsChineseLang = true;
    
	public static int betterStringCompare(String str1, String str2) {
		if (str1 == null || str2 == null) {
			return 0;
		}

		if (sBetterCompareCollator == null) {
			sBetterCompareCollator = Collator.getInstance();
			sBetterCompareCollator.setStrength(Collator.PRIMARY);
			sIsChineseLang = "zh".equals(Locale.getDefault().getLanguage());
		}

		int len1 = str1.length();
		int len2 = str2.length();

		if (sIsChineseLang) {
			if (len1 > 0 && len2 > 0) {
				for (int index = 0; index < len1; index++) {
					char ch1 = str1.charAt(index);
					if (index >= len2) {
						return -1;
					}
					char ch2 = str2.charAt(index);
					if (ch1 != ch2) {
						if ((ch1 >= 0x80 && ch2 < 0x80)
								|| (ch2 >= 0x80 && ch1 < 0x80)) {
							return ch1 < 0x80 ? -1 : 1;
						}
						break;
					}
				}
			}
		}

		int index1 = 0, index2 = 0;
		for (; index1 < len1 && index2 < len2;) {
			int num1 = index1;
			int num2 = index2;
			while (index1 < len1) {
				char ch1 = str1.charAt(index1);
				if (ch1 < '0' || ch1 > '9') {
					break;
				}
				index1++;
			}

			while (index2 < len2) {
				char ch2 = str2.charAt(index2);
				if (ch2 < '0' || ch2 > '9') {
					break;
				}
				index2++;
			}

			int numlen1 = index1 - num1;
			int numlen2 = index2 - num2;

			if (numlen1 != numlen2) {
				if (numlen1 > 0 && numlen2 > 0) {
					int num11 = num1, num22 = num2;
					while (num11 < index1) {
						if (str1.charAt(num11) == '0') {
							num11++;
						} else {
							break;
						}
					}

					while (num22 < index2) {
						if (str2.charAt(num22) == '0') {
							num22++;
						} else {
							break;
						}
					}

					if ((index1 - num11) != (index2 - num22)) {
						return ((index1 - num11) - (index2 - num22));
					}

					while (num11 < index1 && num22 < index2) {
						char ch1 = str1.charAt(num11);
						char ch2 = str2.charAt(num22);
						if (ch1 == ch2) {
							num11++;
							num22++;
							continue;
						}
						return ch1 - ch2;
					}

					// return numlen1 - numlen2;
					return numlen2 - numlen1;// 数字大小相等，长度长的在前
				}

				return sBetterCompareCollator.compare(str1.substring(num1),
						str2.substring(num2));
				// return file1.charAt(num1) - file2.charAt(num2);
			}

			if (numlen1 > 0) {	// numlen1 == numlen2
				while (num1 < index1) {
					char ch1 = str1.charAt(num1);
					char ch2 = str2.charAt(num1);
					if (ch1 == ch2) {
						num1++;
						continue;
					}
					return ch1 - ch2;
				}
			}

			if (index1 >= len1 || index2 >= len2) {
				return len1 - len2;
			}

			char ch1 = str1.charAt(index1);
			char ch2 = str2.charAt(index2);
			if (ch1 <= 'a' && ch1 >= 'z') {
				if (ch2 <= 'A' && ch2 >= 'Z') {
					ch2 += ('a' - 'A');
				}

				if (ch1 != ch2) {
					return ch1 - ch2;
				}
			} else {
				if (ch1 <= 'A' && ch1 >= 'Z') {
					if (ch2 <= 'a' && ch2 >= 'z') {
						ch2 -= ('a' - 'A');
					}

					if (ch1 != ch2) {
						return ch1 - ch2;
					}
				} else {
					if (ch1 != ch2) {
						return sBetterCompareCollator.compare(str1.substring(index1),
								str2.substring(index2));
					}
				}
			}

			index1++;
			index2++;
		}

		return (len1 - len2);
	}
	
	public static long getAvailableStorageSize() {
		if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
			StatFs sf = new StatFs(getExternalStorageDirectory().getAbsolutePath());
			return (long)sf.getBlockSize() * sf.getAvailableBlocks();
		}
		return 0;
	}
	
	public static String validateUnknown(String fileName){
		if(!TextUtils.isEmpty(fileName)){
			if (MediaStore.UNKNOWN_STRING.equals(fileName)) {
	            return null;
	        }else{
	       	 	return fileName;
	        }
		}else{
			return null;
		}		
	}
	
	public static String validateStr(String fileName) {
		if(!TextUtils.isEmpty(fileName)){
			String buffer = null;
			int strLength = fileName.length();
			if (strLength > 0) {
				StringBuffer str = new StringBuffer(strLength);
				char tempChar;
				for (int i = 0; i < strLength; i++) {
					tempChar = fileName.charAt(i);
					if (tempChar == '\\' || tempChar == '/' || tempChar == ':'
							|| tempChar == '*' || tempChar == '?'
							|| tempChar == '\"' || tempChar == '<'
							|| tempChar == '>' || tempChar == '|') {
						str.append('_');
					} else {
						str.append(tempChar);
					}
				}
				buffer = str.toString();			
			}
			return buffer;
		}else{
			return null;
		}		
	}
	
	/**
	 * Purpose:文件是否存在
	 * @param filePath 文件路径
	 * @return
	 */
	public static boolean isFileExists(String filePath) {
		if(!TextUtils.isEmpty(filePath) && !filePath.equals("Default")){
			File f = new File(filePath);
			return f.exists();
		}else{
			return false;
		}		
	}
	
	public static boolean isEmpty(String str) {
		return str == null || str.trim().length() == 0;
	}

	public static boolean copyFile(ThreadPool.JobContext jc, String src, String dst) {
		return copyFile(jc, new File(src), new File(dst));
	}
	
	public static boolean copyFile(ThreadPool.JobContext jc, File src, File dst) {
		boolean success = false;
		FileInputStream input = null;
		FileOutputStream output = null;
		try {
	    	File parent = dst.getParentFile();
	    	if (parent.exists() || parent.mkdirs()) {
    			input = new FileInputStream(src);
	    		output = new FileOutputStream(dst);
    			success = DownloadUtils.dump(jc, input, output);
	    	}
		} catch (Throwable t) {
			t.printStackTrace();
		} finally {
			Utils.closeSilently(input);
			Utils.closeSilently(output);
		}
		if (!success) {
			dst.delete();
		}
		return success;
	}
	
	public static boolean isHasNFC() {
	    boolean flag = false;
	    Method hasNFCMethod;
	    try {
            hasNFCMethod = Build.class.getMethod("hasNFC");
            Object obj = hasNFCMethod.invoke(null);
            flag = (Boolean) obj;
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
	    return flag;
	}
	
	public static File getExternalStorageDirectory() {
		if (sGetStorageDirMethod != null) {
			try {
				return (File)sGetStorageDirMethod.invoke(null);
			} catch (Exception e) {
				return Environment.getExternalStorageDirectory();
			}
		} else {
			return Environment.getExternalStorageDirectory();
		}
	}
	
	public static boolean isSDCardMounted() {
    	return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
    }
	
	/**
     * @author 汉字转拼音
     * @param fileName
     * @return
     */
    public static String getPingYinFromHangzi(String fileName){
        if(TextUtils.isEmpty(fileName)){
            return "#";
        }
        ArrayList<HanziToPinyin.Token> tokens = HanziToPinyin.getInstance().get(fileName);
        if(tokens == null||tokens.size() <= 0)return "#";
        String str = "";
        for(int i=0;i<tokens.size();i++){
            HanziToPinyin.Token t = tokens.get(i);
            str += t.target;
        }
        return str;
    }
    
    /**
     * @description 结束多选模式
     * @param absListView
     */
    public static void finishMultiChoice(AbsListView absListView) {
        try {
            Method b = AbsListView.class.getMethod("finishMultiChoice");
            b.invoke(absListView);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    } 
    
    public static SpannableString makeDeleteTip(Resources res, String title, int count) {
		title += "   ";
		int length = title.length();
		title += count;
		SpannableString spannableTitle = new SpannableString(title);
		spannableTitle.setSpan(new ForegroundColorSpan(/*res.getColor(R.color.media_delete_tip_count)*/0xFFFF0000),
				length, title.length(), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
		return spannableTitle;
	}
    
    /**
     * Converts DIP to pixels.
     * @param dip the value of the dip.
     * @return the value of the pixels.
     */
    public static int dipToPixel(int dip) {
    	float scale = Resources.getSystem().getDisplayMetrics().density;
        return (int) (dip * scale + 0.5f);
    }
    
    public static Drawable getAppIcon(Context context, int defaultResId) {
        PackageManager pm = context.getPackageManager();
        try {
			return pm.getApplicationIcon(context.getPackageName());
		} catch (Exception e) {
			e.printStackTrace();
		}
    	return context.getResources().getDrawable(defaultResId);
    }
    
    
    /**
     * @description 给Activity或者Fragment设置右滑退出
     * @param obj
     * @param enabled
     */
    public static void setEnabledGestureDetector(Object obj, boolean enabled) {
        try {
            Class<?> gestureClass = null;
            if (obj != null) {
            	if (obj instanceof Activity) {
            		gestureClass = Class.forName("android.app.Activity");
            	} else if (obj instanceof android.app.Fragment) {
            		gestureClass = Class.forName("android.app.Fragment");
            	} else if (obj instanceof android.support.v4.app.Fragment) {
            		gestureClass = Class.forName("android.support.v4.app.Fragment");
            	}
            	
            	if (gestureClass != null) {
            		Method method = gestureClass.getMethod("setEnabledGestureDetector", boolean.class);            		
            		method.invoke(obj,  enabled); 
            	}
            }                       
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    } 


    
    /**
     * @description 设置列表内容不满屏时居中显示.
     * @param absListView
     */
    public static void setCenterListContent(AbsListView absListView, boolean centerContent) {
        try {
            Method b = AbsListView.class.getMethod("setCenterListContent", boolean.class);
            b.invoke(absListView, centerContent);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    } 
    
	public static boolean equals(String str1, String str2) {
		if (str1 == null && str2 == null) {
			return true;
		}
		if (str1 == null || str2 == null) {
			return false;
		}
		return str1.equals(str2);
	}
    
    public static boolean ifHasPermanentkey() {
    	boolean hasPerKey = true;
    	
		String device = Build.DEVICE;
		if (device.equals("mx") || device.equals("m9")) {
			hasPerKey = true;
		} else {
			hasPerKey = false;
		}
		Log.d(TAG, "device="+device);
    	
    	return hasPerKey;
    }
    
    public static boolean ifMeizuPhone() {
    	boolean ifMeizu = false;
    	String device = Build.DEVICE;
		if (device.equals("m75") || device.equals("mx3") || device.equals("mx2") || device.equals("mx") || device.equals("m9")) {
			ifMeizu = true;
		}
		Log.d(TAG, "device="+device);
    	return ifMeizu;
    }
    
    /**
     * 用于获取string的绝对hash，重复率低
     * @param str
     * @return
     * from wangdong
     */
    public static String getHash(String str) {
    	int hash1 = APHash(str);
    	int hash2 = ELFHash(str);
    	return String.valueOf(hash1) + String.valueOf(hash2);
    }
    private static int APHash(String str) {
        int hash = 0;

        for (int i = 0; i < str.length(); i++) {
            hash ^= ((i & 1) == 0) ? ((hash << 7) ^ str.charAt(i) ^ (hash >> 3))
                    : (~((hash << 11) ^ str.charAt(i) ^ (hash >> 5)));
        }
        return hash;
    }
    private static int ELFHash(String str) {
        int hash = 0;
        int x = 0;

        for (int i = 0; i < str.length(); i++) {
            hash = (hash << 4) + str.charAt(i);
            if ((x = (int) (hash & 0xF0000000L)) != 0) {
                hash ^= (x >> 24);
                hash &= ~x;
            }
        }
        return hash & 0x7FFFFFFF;
    }
    
	/**
	 * @description 设置下拉悬停HOLD提示离列表顶部位置.
	 * @param absListView
	 * @param offset
	 */
    public static void setDelayTopOverScrollOffset(AbsListView absListView, int offset) {
        try {
            Method b = AbsListView.class.getMethod("setDelayTopOverScrollOffset", int.class);
            b.invoke(absListView, offset);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
    
	public static String getSystemProperties(String key, String def) {
		try {
			Class<?> clazz = Class.forName("android.os.SystemProperties");
			Class<?>[] classes = new Class[]{ String.class, String.class };
			Method method = clazz.getMethod("get", classes);
			Object[] params = new Object[] { key, Build.UNKNOWN };
            return (String)method.invoke(null, params);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		return null;
	}
    
    //<<系统属性相关
	
	private static String sPhoneSn = null;
	public synchronized static String getPhoneSn() {
		if (sPhoneSn == null) {
			if ("Meizu".equalsIgnoreCase(Build.MANUFACTURER)) {
				sPhoneSn = getSystemProperties("ro.serialno", null);
			} else {
				sPhoneSn = Build.SERIAL;
			}
		}
		return sPhoneSn;
	}
	
	private static int sInternational = -1;
	public synchronized static boolean isInternational() {
		if (sInternational == -1) {
			if (!(getSystemProperties("ro.product.locale.language", null).equals("zh")
					&& getSystemProperties("ro.product.locale.region", null).equals("CN"))) {
				sInternational = 1;
			} else {
				sInternational = 0;
			}
		}
		return sInternational == 1;
	}

	private static String sIsShopDemo = null;
	/** 是否是专卖店版本 */
	public static boolean isShopDemo() {
		if (sIsShopDemo == null) {
			sIsShopDemo = getSystemProperties("ro.meizu.customize.demo",
					Build.UNKNOWN);
		}
		return "true".equals(sIsShopDemo);
	}

	private static String sIsFlymeRom = null;
	/** 判断是否是flymeRom为其它手机做的适配 */
	public static boolean isFlymeRom() {
		if (sIsFlymeRom == null) {
			sIsFlymeRom = getSystemProperties("ro.meizu.rom.config",
					Build.UNKNOWN);
		}
		return "true".equals(sIsFlymeRom);
	}

	private static String sIsChinaMobile = null;
	/** 是否是移动定制版本 */
	public static boolean isChinaMobile() {
		if (sIsChinaMobile == null) {
			sIsChinaMobile = getSystemProperties("ro.customize.isp",
					Build.UNKNOWN);
		}
		return "chinamobile".equals(sIsChinaMobile);
	}
	
	private static String sIsMeizuM71 = null;
	/** 是否是m71手机 */
	public static boolean isMeizuM71() {
		if (sIsMeizuM71 == null) {
			sIsMeizuM71 = getSystemProperties("ro.product.model",
					Build.UNKNOWN);
		}
		return "m71".equals(sIsMeizuM71) || "m1 note".equals(sIsMeizuM71) || "k52v2".equals(sIsMeizuM71);
	}
    private static String sIsMeizuM79 = null;
    /** 是否是m79手机 */
    public static boolean isMeizuM79() {
        if (sIsMeizuM79 == null) {
            sIsMeizuM79 = getSystemProperties("ro.product.model",
                    Build.UNKNOWN);
        }
        return "m79".equals(sIsMeizuM79) || "m1".equals(sIsMeizuM79) || "k32v2".equals(sIsMeizuM79);
    }

	private static String sIsHifi = null;
	/** 是否是hifi */
	public static boolean isHifiDevice() {
		if (sIsHifi == null) {
			sIsHifi = getSystemProperties("ro.meizu.hardware.hifi",
					Build.UNKNOWN);
		}
		return "true".equals(sIsHifi);
	}
	
	//系统属性相关>>
    
}
